# Create your forms here.

from django import forms
from django.forms import ModelForm

from psd.register.models import Person, RegRecord, GENDERS, LOCATIONS, KINKINESSES

class PSDMultipleChoiceField(forms.MultipleChoiceField):
    def to_python(self, value):
        return value.split(",")
    def clean(self, value):
        return ",".join(value)
    def validate(self, value):
        pass
    def run_validators(self, value):
        pass

class PSDCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
    def render(self, name, value, attrs=None, choices=()):
        new_value = value
        if isinstance(value, basestring):
          new_value = value.split(",")
        return forms.CheckboxSelectMultiple.render(self, name, new_value, attrs, choices)# + repr((value, new_value))

class PersonForm(ModelForm):
    gender = PSDMultipleChoiceField(choices=GENDERS, widget=PSDCheckboxSelectMultiple, label="Gender")
    seek_gender = PSDMultipleChoiceField(choices=GENDERS, widget=PSDCheckboxSelectMultiple, label="Gender Wanted")
    age = forms.IntegerField(widget=forms.TextInput(attrs={'size': 5}))
    seek_age_min =  forms.IntegerField(widget=forms.TextInput(attrs={'size': 5}))
    seek_age_max =  forms.IntegerField(widget=forms.TextInput(attrs={'size': 5}))
    seek_kinkiness = forms.ChoiceField(choices=KINKINESSES, initial='EI')

    class Meta:
        model = Person

class RegRecordForm(ModelForm):
    location = PSDMultipleChoiceField(required=False, choices=LOCATIONS, widget=PSDCheckboxSelectMultiple)
    nickname = forms.CharField(widget=forms.TextInput(attrs={'size': 25}))
    email = forms.CharField(widget=forms.TextInput(attrs={'size': 25}))
    referred_by = forms.CharField(required=False, widget=forms.TextInput(attrs={'size': 45}))
    comments = forms.CharField(required=False, widget=forms.Textarea(attrs={'cols':40,'rows':3}))

    class Meta:
        model = RegRecord
        exclude = ('people',)

### GENDERS = (
###     ('M', 'male'),
###     ('F', 'female'),
###     ('TM', 'trans male'),
###     ('TF', 'trans female'),
###     ('Q', 'genderqueer'),
### )

### class PersonForm(forms.Form):
###     first_name = forms.CharField()
###     last_name = forms.CharField()
###     nickname = forms.CharField()
###     email = forms.EmailField()
###     add_to_mailings = forms.BooleanField(required=False)
###     gender = forms.MultipleChoiceField(choices=GENDERS)
###     age = forms.IntegerField(min_value=18)
###     seeking_primary = forms.BooleanField(required=False)
###     kinky = forms.BooleanField(required=False)
###     seek_gender = forms.MultipleChoiceField(choices=GENDERS)
###     seek_age_min = forms.IntegerField(min_value=18, required=False)
###     seek_age_max = forms.IntegerField(required=False)
###     seek_kinkiness = forms.NullBooleanField()
###     seek_groups = forms.NullBooleanField()
###     friend_dates = forms.BooleanField(required=False)
###     referred_by = forms.CharField(max_length=30, required=False)
###     location = forms.CharField(max_length=30, required=False)
###     wants_childcare = forms.BooleanField(required=False)
###     comments = forms.CharField(required=False)
